import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLoggedIn: false,
    user: null,
    categories: [
      { id: 1, name: '玄幻' },
      { id: 2, name: '奇幻' },
      { id: 3, name: '武侠' },
      { id: 4, name: '仙侠' },
      { id: 5, name: '都市' },
      { id: 6, name: '灵异' }
    ]
  },
  mutations: {
    setLoggedIn(state, value) {
      state.isLoggedIn = value
    },
    setUser(state, user) {
      state.user = user
    }
  },
  actions: {
    login({ commit }, user) {
      commit('setUser', user)
      commit('setLoggedIn', true)
    },
    logout({ commit }) {
      commit('setUser', null)
      commit('setLoggedIn', false)
    }
  },
  getters: {
    isLoggedIn: state => state.isLoggedIn,
    user: state => state.user,
    categories: state => state.categories
  }
}) 